<?php
function icomet_push($cname, $content){
	$cname = urlencode($cname);
	$content = urlencode($content);
	$url = "http://127.0.0.1:8000/push?cname=$cname&content=$content";

	$ch = curl_init($url) ;
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
	$result = curl_exec($ch) ;
	curl_close($ch) ;
	return $result;
}

if(get_magic_quotes_gpc()){
	$_GET['content'] = stripslashes($_GET['content']);
}
$cname = trim($_GET['cname']);
$content = trim($_GET['content']);

echo icomet_push($cname, $content);


// 写入mongodb
$manager = new \MongoDB\Driver\Manager('mongodb://127.0.0.1:27017');

$bulk = new \MongoDB\Driver\BulkWrite();

$document = array(
		'cname' => $cname,
		'content' => $content,
	);

$objectId = $bulk->insert($document);

$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);

$result = $manager->executeBulkWrite('chat.channel'.$cname, $bulk, $writeConcern);